<!-- 订单信息 -->
<template>
  <div class="BillDetails">
    <!-- 顶部导航栏 吸顶 -->
    <van-sticky>
      <van-nav-bar title="订单信息">
        <template #left>
          <van-icon name="arrow-left" color="#fff" @click="goBack">返回</van-icon>
        </template>
      </van-nav-bar>
      <div class="avatar">
        <van-image width="100px" height="100px" :src="avatar"/>
      </div>
      <div class="name" v-if="bill[index].state">+¥{{bill[index].price.toFixed(2)}}</div>
      <div class="name" v-else>-¥{{Math.abs(bill[index].price).toFixed(2)}}</div>
    </van-sticky>

    <van-cell title="订单时间" :value="bill[index].details.time" icon="underway-o" />

    <table border="0" cellspacing="1">
      <thead>
        <th class="width-50">序号</th> <th>商品名称</th> <th>商品数量</th> <th>商品价格</th>
      </thead>
      <tbody v-for="(item,i) in bill[index].details.commodity" :key="i">
        <th>{{i+1}}</th> <th>{{item.name}}</th> <th>x{{item.num}}</th> <th>¥{{item.price}}</th>
      </tbody>
    </table>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  data(){
    return{
      
    }
  },
  computed:{
    ...mapState(["avatar","bill"]),
  },
  created(){
    this.index = this.$route.params.index;
  },
  methods:{
    // 返回
    goBack() {
      this.$router.go(-1);
    },
  }
}
</script>

<style lang="scss" scoped>
.BillDetails{
  .van-nav-bar{
    background-color: $base-color;
    ::v-deep .van-nav-bar__title{
      font-weight: bold;
    }
    .van-icon{
      font-weight: bold;
    }
  }
  .avatar{
    display: flex;
    justify-content: center;
    margin-top: 20px;
  }
  .name{
    text-align: center;
    font-weight: bold;
    margin: 10px;
  }
  table{
    width: 100%;
    border-radius: 10px;
    margin: 12px 0;
    padding: 0 12px;
    overflow: hidden;
    thead{
      background-color: rgb(230,238,251);
      th{
        padding: 10px;
        width: 100px;
      }
    }
    tbody{
      background-color: oldlace;
      th{
        font-weight: 400;
        padding: 4px;
      }
    }
  }
}
</style>